package com.example.login.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class CarDbHelper extends SQLiteOpenHelper {

    private static CarDbHelper carDbHelper;
    private static final String DB_NAME = "car.db";

    private static final int VERSION = 1;

    public CarDbHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    // 创建单例，供curd使用
    public synchronized static CarDbHelper getInstance(Context context) {
        if (null == carDbHelper) {
            carDbHelper = new CarDbHelper(context, DB_NAME, null, VERSION);
        }
        return carDbHelper;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table car_table(_id integer primary key autoincrement, " +
                "username text," +
                "product_id text," +
                "product_img integer," +
                "product_title text," +
                "product_price integer" + // 这里的, 要删掉
                ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
